package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.commons.response.JsonResult;
import cn.tedu.csmall.passport.pojo.dto.AdminLoginDTO;
import cn.tedu.csmall.passport.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @GetMapping("/hello")
    @PreAuthorize("hasAuthority('/ams/admin/read')")
    public JsonResult<Void> sayHello() {
        return JsonResult.ok();
    }

    @PostMapping("/login")
    public JsonResult<String> login(AdminLoginDTO adminLoginDTO) {
        return JsonResult.ok(adminService.login(adminLoginDTO));
    }

}
